// 
//  Copyright (C) 2009 Jacek Trubłajewicz
// 
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
// 
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// 

using System;
using System.Drawing;
using Mono.Unix;
using NLog;

namespace wxGadu
{
	/// <summary>
	/// Represents window with information 
	/// about application
	/// </summary>
	public class AboutDialog : wx.Dialog
	{
		private wx.Button okButton;
		private wx.StaticBitmap monoBitmap;
		private wx.StaticBitmap wxBitmap;
		private wx.StaticText appName;
		private wx.TextCtrl lyric;
		private MainFrame mainFrame;
		private AssemblyInfo ainfo;
		
		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="parent">
		/// A <see cref="wx.Window"/>
		/// </param>
		public AboutDialog(wx.Window parent):
			base(parent, wx.Window.wxID_ANY, Catalog.GetString("About"), wx.Window.wxDefaultPosition, 
			     wx.Window.wxDefaultSize)
		{
			ainfo = new AssemblyInfo();
			mainFrame = (MainFrame) parent;
			CreateControls();
			DoLayout();
			this.CenterOnScreen();
		}
		
		private void CreateControls()
		{
			okButton = new wx.Button(this, wx.Window.wxID_OK, "&OK");
			okButton.SetDefault();
			
			wx.Image img = mainFrame.ImageMgr[ImageManager.MONO].ConvertToImage();
			img = img.Rotate90(false);
			monoBitmap = new wx.StaticBitmap(this, new wx.Bitmap(img));
			
			img = mainFrame.ImageMgr[ImageManager.WXWIDGETS].ConvertToImage();
			img = img.Rotate90(false);
			wxBitmap = new wx.StaticBitmap(this, new wx.Bitmap(img));
			
			appName = new wx.StaticText(this, -1, string.Format("{0} {1}", ainfo.Title, ainfo.Version),
			                            wx.Window.wxDefaultPosition, wx.Window.wxDefaultSize,
			                            wx.Alignment.wxALIGN_CENTER);
			appName.Font = new wx.Font(15, wx.FontFamily.wxNORMAL, wx.FontStyle.wxNORMAL,
			                           wx.FontWeight.wxBOLD);
			
//			author.Enable(false);
			string about = Catalog.GetString("Instant messanger written in C#, based on wxWidgets.Net gui libs. wxGadu is using popular in Poland Gadu-Gadu instant messaging network.");
			string author = "\n\n\n\n\n\nCopyright: \n" + ainfo.Copyright;
			lyric = new wx.TextCtrl(this, -1, about + author, 
			                           wx.Window.wxDefaultPosition, new Size(300, 180),
			                          wx.TextCtrl.wxTE_MULTILINE|wx.TextCtrl.wxTE_READONLY|wx.Window.wxNO_BORDER|
			                        wx.TextCtrl.wxTE_CENTER);
			lyric.BackgroundColour = this.BackgroundColour;
//			lyric.Enable(false);
		}
		
		private void DoLayout()
		{
			wx.BoxSizer topSizer = new wx.BoxSizer(wx.Orientation.wxVERTICAL);
			{
				wx.BoxSizer boxSizer = new wx.BoxSizer(wx.Orientation.wxVERTICAL);
				{
					boxSizer.Add(20, 5, 0, wx.Alignment.wxALIGN_CENTER_HORIZONTAL, 0);
					
					wx.BoxSizer insideSizer = new wx.BoxSizer(wx.Orientation.wxHORIZONTAL);
					{
						wx.BoxSizer graphicSizer = new wx.BoxSizer(wx.Orientation.wxVERTICAL);
						{
							graphicSizer.Add(10, 20);
							graphicSizer.Add(monoBitmap, 0, 0, 0);
							graphicSizer.Add(20, 10);
							graphicSizer.Add(wxBitmap, 0, 0, 0);
							graphicSizer.Add(10, 20);
						}
						insideSizer.Add(graphicSizer, 0, wx.Stretch.wxEXPAND|
						                wx.Direction.wxALL, 5);
						
						wx.StaticLine line = new wx.StaticLine(this, -1, wx.Window.wxDefaultPosition,
						                                       wx.Window.wxDefaultSize, wx.StaticLine.wxLI_VERTICAL);
						insideSizer.Add(line, 0, wx.Stretch.wxEXPAND);
						
						wx.BoxSizer textSizer = new wx.BoxSizer(wx.Orientation.wxVERTICAL);
						{
							textSizer.Add(10, 20, 0, 0, 0);
							
							textSizer.Add(appName, 0, wx.Direction.wxBOTTOM|wx.Alignment.wxALIGN_CENTER_HORIZONTAL, 15);
							
							textSizer.Add(lyric, 0, wx.Direction.wxALL, 5);
													
							textSizer.Add(20, 20, 2, 0, 0);
							
						}
						insideSizer.Add(textSizer, 1, wx.Stretch.wxEXPAND|wx.Direction.wxLEFT, 10);
					}
					boxSizer.Add(insideSizer, 1, wx.Stretch.wxEXPAND);
					
					boxSizer.Add(okButton, 0, wx.Alignment.wxALIGN_CENTER_HORIZONTAL|
					             wx.Direction.wxTOP, 5);
				}
				topSizer.Add(boxSizer, 1, wx.Stretch.wxEXPAND|wx.Direction.wxALL, 10);
			}
			this.Sizer = topSizer;
			topSizer.Fit(this);
			topSizer.SetSizeHints(this);
		}
	}
}
